package com.mgg.goods.controller;

import com.mgg.common.util.ResultVOUtil;
import com.mgg.goods.service.category.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
public class CategoryController {

	@Autowired
	private CategoryService categoryService;
	
	/**
	 * 获取所有商品分类
	 * @return
	 * @throws Exception
	 */
	@GetMapping(path="/list")
	public Object findCategoryList() {
		return ResultVOUtil.success(categoryService.listCategory());
	}
	
	/**
	 * 获取商品一级类目
	 * @return
	 * @throws Exception
	 */
	@GetMapping(path="/list/first")
	public Object findFirstCategoryList() {
		return ResultVOUtil.success(categoryService.listFirstCategory());
	}
	
	/**
	 * 获取商品二级类目
	 * @param categoryId
	 * @return
	 * @throws Exception
	 */
	@GetMapping(path="/list/second")
	public Object findSecondCategoryList(@RequestParam(value="catgId", required=true) String categoryId) {
		return ResultVOUtil.success(categoryService.listSecondCategory(categoryId));
	}
}
